<template>
	<view>
		<view class="head">
			<text @click="back">返回</text>
			<text>新增</text>
		</view>
		<view class="body">
				<form @submit="onSubmit" @reset="formReset">
					<picker @change="bindPickerChange1" :value="date.index" :range="date.arr">
						<uni-forms-item label="单位名称" name="dwname">
							<uni-easyinput type="text" v-model="date.shujudata.dwname" placeholder="请选择" />
						</uni-forms-item>
						</picker>
				<picker @change="bindPickerChange2" :value="date.index" :range="date.arr1">
						<uni-forms-item label="是否按照批准的取水" name="qsd">
							<uni-easyinput type="text" v-model="date.shujudata.qsd" placeholder="请选择" />
						</uni-forms-item>
						</picker>
						<picker @change="bindPickerChange3" :value="date.index" :range="date.arr1">
								<uni-forms-item label="是否改造取水设施" name="qsshebei">
									<uni-easyinput type="text" v-model="date.shujudata.qsshebei" placeholder="请选择" />
								</uni-forms-item>
								</picker>
								<picker @change="bindPickerChange4" :value="date.index" :range="date.arr1">
										<uni-forms-item label="计量设施" name="jlshebei">
											<uni-easyinput type="text" v-model="date.shujudata.jlshebei" placeholder="请选择" />
										</uni-forms-item>
										</picker>
										<picker @change="bindPickerChange5" :value="date.index" :range="date.arr1">
												<uni-forms-item label="工作记录" name="workjlu">
													<uni-easyinput type="text" v-model="date.shujudata.workjlu" placeholder="请选择" />
												</uni-forms-item>
												</picker>
												<picker @change="bindPickerChange6" :value="date.index" :range="date.arr1">
														<uni-forms-item label="水量" name="shuiliang">
															<uni-easyinput type="text" v-model="date.shujudata.shuiliang" placeholder="请选择" />
														</uni-forms-item>
														</picker>
														<uni-forms-item label="检查情况" name="jiancha">
														<view class="uni-textarea">
																	<textarea  auto-height v-model="date.shujudata.jiancha" placeholder-style="color:#B3D4FC" placeholder="请输入....."/>
																	</view>
																	</uni-forms-item>
																	<uni-section title="只选择图片" type="line">
																				<view class="example-body">
																					<uni-file-picker limit="3" title="现场照片(最多选择3张图片)" v-model="date.img"
																					fileMediatype="image" 
																					@select='pushimg'
																					></uni-file-picker>
																				</view>
																			</uni-section>
																	<view class="uni-btn-v">
																		<button  type="default" class="color"  size="mini"  form-type="submit">提交</button>
																		<button type="default"  class="color" size="mini" form-type="reset">重置</button>
																	</view>
					</form>
		</view>
	</view>
</template>

<script>
	// export default {
	// setup(){
	// 	let back=()=>{
	    import {reactive} from 'vue';
	    import {useStore} from "vuex"
		import http from '../../utils/http.js'
		import upload from '../../utils/upload.js'
	export default{ 	
	setup(){
		let date=reactive({
			arr:['华为','小米','oppo','vivo','魅族'],
			arr1:['正常','异常'],
			shujudata:{dwname:'',
			qsd:'',
			qsshebei:'',
			jlshebei:'',
			workjlu:"",
			shuiliang:'',
			jiancha:'',
			jctime:''},
			index:0,
			img:[],
			imgdata:[]
			
			
		})
let back=()=>{
			uni.navigateTo({
				url:'./richangjiancha'
			})
		}
		return{
			back
		}
let onSubmit=()=>{
			let data=new Date()
			let year=data.getFullYear()
			let month=jisuan(data.getMonth()+1)
			let day=data.getDate()
			let time=year+'-'+month+'-'+day
			date.shujudata.jctime=time
			http({
				url:'/jiliang/jianchaadd',
				method:'post',
				data:date.shujudata
			}).then((res)=>{
				if(res.data.code==200){
					for(let i=0;i<date.imgdata.length;i++){
						upload({
									url: '/jiliang/uploads', //仅为示例，非真实的接口地址
									filePath: date.imgdata[i],
									name: 'file',
									formData:{}
								}).then((res)=>{
								console.log(res)
								
								})
					}
					uni.showToast({
						title:'添加成功',
					})
					back()	
				}
				
				if(res.data.code==401){
					formReset()
					uni.showToast({
						title:'添加失败，数据已存在.',
						icon:'error'
					})
				}
			})
			
		}
		let bindPickerChange1=(e)=>{
			date.shujudata.dwname=date.arr[e.detail.value]
		}
			let bindPickerChange2=(e)=>{
				date.shujudata.qsd=date.arr1[e.detail.value]
				}
				let bindPickerChange3=(e)=>{
					date.shujudata.qsshebei=date.arr1[e.detail.value]
					}
					let bindPickerChange4=(e)=>{
						date.shujudata.jlshebei=date.arr1[e.detail.value]
						}
						let bindPickerChange5=(e)=>{
							date.shujudata.workjlu=date.arr1[e.detail.value]
							}
							let bindPickerChange6=(e)=>{
								date.shujudata.shuiliang=date.arr1[e.detail.value]
								}
		let formReset=()=>{
			
		}
		let pushimg=(ev)=>{
			// date.img=ev.tempFiles
			date.img=ev.tempFiles
			date.imgdata=ev.tempFilePaths
				}
		let jisuan=(v)=>{
			return v>9?''+v:'0'+v;
		}
		return{
			back,
			bindPickerChange1,
			bindPickerChange2,
			bindPickerChange3,
			bindPickerChange4,
			bindPickerChange5,
			bindPickerChange6,
			formReset,
			onSubmit,
			date,
			jisuan,
			 pushimg,
	}
	}
	}
</script>

<style lang="less">
.color{
		background-color: #B3D4FC;
		
	}

.head {
		display: flex;
		padding: 30rpx 0 30rpx 50rpx;
		border-bottom: 1rpx solid #969896;

		text:first-child {
			flex: 2;
			color: #B3D4FC;
		}

		text:last-child {
			flex: 3;
		}
	}

	.uni-btn-v{
		display: flex;
		text-align: center;
		flex-direction: column;
		margin-top: 200rpx;
		button{
			margin:25rpx auto;
		}
	}
	.body {
		margin-top: 30rpx;
		padding: 20rpx;
	}
</style>
